package org.strieber.fca.mid3;

import java.util.ArrayList;
import java.util.List;

import org.strieber.fca.Rule;

public class DecisionNode {

	private DecisionNode parent = null;
	private List<DecisionNode> children = null;
	private List<Rule> rules = new ArrayList<Rule>();
	
	private String attributeSplitOn = "";
	private String valueSplitOn = "";
	
	public double entropy = 0;
	
	public DecisionNode() {
		
	}
	
	public DecisionNode(DecisionNode parent, List<DecisionNode> children, List<Rule> rules, String attributeSplitOn, String valueSplitOn, double entropy) {
		this.parent = parent;
		this.children = children;
		this.rules = rules;
		this.attributeSplitOn = attributeSplitOn;
		this.valueSplitOn = valueSplitOn;
		this.entropy = entropy;
	}
	
	public void setAttributeSplitOn(String attributeSplitOn) {
		this.attributeSplitOn = attributeSplitOn;
	}
	
	public String getAttributeSplitOn() {
		return attributeSplitOn;
		
	}
	
	public void setValueSplitOn(String valueSplitOn) {
		this.valueSplitOn = valueSplitOn;
	}
	
	public String getValueSplitOn() {
		return valueSplitOn;
		
	}
	
	public void setParent(DecisionNode parent) {
		this.parent = parent;
	}
	
	public DecisionNode getParent() {
		return parent;
	}
	
	public void setRules(List<Rule> rules) {
		this.rules = rules;
	}
	
	public List<Rule> getRules() {
		return rules;
	}
	
	public void setEntropy(double entropy) {
		this.entropy = entropy;
	}
	
	public double getEntropy() {
		return entropy;
	}
	
	public void addChild(DecisionNode child) {
		if (children == null) {
			children = new ArrayList<DecisionNode>();
		}
		children.add(child);
	}
	
	public void removeChild(int index) {
		children.remove(index);
		if (children.size() == 0) {
			children = null;
		}
	}
	
	public void setChildren(List<DecisionNode> children) {
		this.children = children;
	}
	
	public List<DecisionNode> getChildren() {
		return children;
	}
	
	public String toString() {
		if (parent == null) {
			return "root node";
		}
		return "-- " + parent.getAttributeSplitOn() + "=" + valueSplitOn + " -- [ " + rules + "] -->";
	}
}